package com.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.model.OrderDetail;
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import com.service.OrderDetailService;

@Configuration
@RestController
public class Controller {
	
	@Autowired
	private OrderDetailService service;
		
	@RequestMapping(value = "/mergeDemo", method = RequestMethod.GET)
	public List<OrderDetail> hystrixMergeDemo() throws Exception {
		
		HystrixRequestContext context = HystrixRequestContext
				.initializeContext();
		
		Future<OrderDetail> f1 = service.getOneOrderDetail("1");
		Future<OrderDetail> f2 = service.getOneOrderDetail("2");
		Future<OrderDetail> f3 = service.getOneOrderDetail("3");
		OrderDetail o1 = f1.get();
		OrderDetail o2 = f2.get();
		OrderDetail o3 = f3.get();
	
		List<OrderDetail> orderDetailList = new ArrayList<OrderDetail>();
		orderDetailList.add(o1);
		orderDetailList.add(o2);
		orderDetailList.add(o3);
		
		context.shutdown();
		
		return orderDetailList;
		
		
		

	}
}
